package com.voja.workoutrandomizer;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import com.voja.AndroidUtils.Application;
import com.voja.workoutrandomizer.repository.Exercise;
import com.voja.workoutrandomizer.repository.Workout;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class Workouts extends Activity {

	private Workout workout;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.workout);
		
		Application.setContext(this);
		
		Bundle extras  = getIntent().getExtras();
		String json = extras.getString("workout");
		try {
			workout = new Workout(new JSONObject(json));
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		randomize(null);
	}
	
	public void display() {
		String debug = "Up:";
		ArrayList<Exercise> up = Main.workouts.getGroup("Up");
		for (int i=0; i<up.size(); i++) {
			debug += "\n\t " + (i+1) + ". " + up.get(i).getName();
		}
		
		debug += "\n\nDown:";
		ArrayList<Exercise> down = Main.workouts.getGroup("Down");
		for (int i=0; i<down.size(); i++) {
			debug += "\n\t " + (i+1) + ". " + down.get(i).getName();
		}
		
		TextView tvDebug = (TextView)findViewById(R.id.tvDebug);
		tvDebug.setText(debug);
		tvDebug.setTextColor(Color.parseColor("#000000"));
		tvDebug.setVisibility(View.VISIBLE);
	}
	
	public void randomize(View v) {
		Main.workouts.randomize();
		display();
	}
	
}
